package com.dd.admin.business.sellDetail.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.dd.admin.common.model.UpdateGroup;
import com.dd.admin.common.model.result.ResultBean;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotBlank;
import com.dd.admin.business.sellDetail.entity.SellDetail;
import com.dd.admin.business.sellDetail.domain.SellDetailVo;
import com.dd.admin.business.sellDetail.domain.SellDetailDto;
import com.dd.admin.business.sellDetail.service.SellDetailService;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单详情 前端控制器
 * </p>
 *
 * @author 727869402@qq.com
 * @since 2024-06-19
 */
@Api(tags = "订单详情")
@RestController
public class SellDetailController {

    @Autowired
    SellDetailService sellDetailService;

    @ApiOperation(value = "订单详情-分页列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("/admin/sellDetail/page")
    public ResultBean<IPage<SellDetailVo>> page(SellDetailDto sellDetailDto) {
        IPage<SellDetailVo> pageInfo = sellDetailService.selectSellDetailPage(sellDetailDto);
        return ResultBean.success(pageInfo);
    }

    @ApiOperation(value = "订单详情-列表")
    @ApiOperationSupport(order = 2)
    @GetMapping("/admin/sellDetail/list")
    public ResultBean<List<SellDetailVo>> list(SellDetailDto sellDetailDto) {
        List<SellDetailVo> list = sellDetailService.selectSellDetailList(sellDetailDto);
        return ResultBean.success(list);
    }

    @ApiOperation(value = "订单详情-添加")
    @ApiOperationSupport(order = 3)
    @PostMapping("/admin/sellDetail/add")
    public ResultBean<SellDetail> add(@RequestBody @Validated SellDetailDto sellDetailDto) {
        SellDetail sellDetail = BeanUtil.copyProperties(sellDetailDto, SellDetail.class);
        sellDetailService.save(sellDetail);
        return ResultBean.success(sellDetail);
    }

    @ApiOperation(value = "订单详情-查询")
    @ApiOperationSupport(order = 4)
    @GetMapping("/admin/sellDetail/{sellDetailId}")
    public ResultBean<SellDetailVo> get(@PathVariable @NotBlank String sellDetailId) {
        SellDetail sellDetail = sellDetailService.getById(sellDetailId);
        SellDetailVo sellDetailVo = BeanUtil.copyProperties(sellDetail,SellDetailVo.class);
        return ResultBean.success(sellDetailVo);
    }

    @ApiOperation(value = "订单详情-修改")
    @ApiOperationSupport(order = 5)
    @PostMapping("/admin/sellDetail/update")
    public ResultBean<SellDetail> update(@RequestBody @Validated(UpdateGroup.class) SellDetailDto sellDetailDto) {
        SellDetail sellDetail = BeanUtil.copyProperties(sellDetailDto, SellDetail.class);
        sellDetailService.updateById(sellDetail);
        return ResultBean.success(sellDetail);
    }

    @ApiOperation(value = "订单详情-删除")
    @ApiOperationSupport(order = 6)
    @GetMapping("/admin/sellDetail/delete/{sellDetailId}")
    public ResultBean<SellDetail> delete(@PathVariable @NotBlank String sellDetailId) {
        Boolean b = sellDetailService.removeById(sellDetailId);
        return ResultBean.success(b);
    }
}
